#!/usr/bin/env python 
#coding=utf8

# date:		2015/07/13
# Author:	jizhuofeng
# Version:	python 2.7

import httplib
import time
import urllib
import sys
import os
import json
ISOTIMEFORMAT='%Y-%m-%d %X'
class http_request():
	def __init__(self, argv):

		self.url = '/v1/driverIn?from=test'
		self.body = {
				'licenseplate': argv[1],
				'pluuid': argv[2],
				'laneid': argv[3],
				'time': time.strftime(ISOTIMEFORMAT, time.localtime())
		}
	def run(self):

		self.host = "api.uwaytech.cn"
		self.headers = {"Content-Type":"application/json"}
		httpClient = None
		try:

			params = json.dumps(self.body)
			headers = {"Content-type": "application/json"
						, "Accept": "text/plain"}
					 
			httpClient = httplib.HTTPSConnection(self.host,58113, timeout=30)
			httpClient.request("POST", self.url, params, headers)
					 
			response = httpClient.getresponse()
			#print response.status
			#print response.reason
			print response.read()
			print response.getheaders() #获取头部信息
		except Exception, e:
			print e
		finally:
			if httpClient:
				httpClient.close()

def help():
	print "input argv (licenseplate, pluuid , entergate)"

if __name__ == '__main__':
	if len(sys.argv) != 4:
		help()
		sys.exit(2)
	
	ob = http_request(sys.argv)
	ob.run()
	
